<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple Web Service Example</title>
</head>
<body>
<h1>Simple Web Service Example</h1>

<form id="myForm">
    <label for="dataInput">Enter Data:</label>
    <input type="text" id="dataInput" name="dataInput">
    <br>
    <button type="button" onclick="sendGetRequest()">Send GET Request</button>
    <button type="button" onclick="sendPostRequest()">Send POST Request</button>
</form>

<div id="response"></div>

<script>
    function sendGetRequest() {
        let xhr = new XMLHttpRequest();
        xhr.open('GET', 'http://localhost:8080/useServlet_war_exploded/simple', true);

        xhr.onload = function() {
            if (xhr.status >= 200 && xhr.status < 300) {
                document.getElementById('response').innerText = xhr.responseText;
            } else {
                document.getElementById('response').innerText = 'Error: ' + xhr.status;
            }
        };

        xhr.send();
    }

    function sendPostRequest() {
        let xhr = new XMLHttpRequest();
        xhr.open('POST', 'http://localhost:8080/useServlet_war_exploded/simple', true);
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

        let formData = new FormData();
        formData.append('data', document.getElementById('dataInput').value);

        xhr.onload = function() {
            if (xhr.status >= 200 && xhr.status < 300) {
                document.getElementById('response').innerText = xhr.responseText;
            } else {
                document.getElementById('response').innerText = 'Error: ' + xhr.status;
            }
        };

        xhr.send(formData);
    }
</script>
</body>
</html>
